package com.bank.user.controller;

import com.bank.common.commonUtil.AuthContextHolderUtil;
import com.bank.common.stringUtil.JwtUtils;
import com.bank.model.entity.User;
import com.bank.model.vo.loan.LoanVo;
import com.bank.model.vo.login.PersonalInfoVo;
import com.bank.model.vo.user.MainpageVo;
import com.bank.model.vo.user.UserBasicInfoVo;
import com.bank.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author Cejay1314
 * @version 1.0
 * @create 2023/3/23 22:24
 */


@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    UserService userService;

    //    查询个人信息
    @GetMapping("/info")
    public PersonalInfoVo queryInfo(HttpServletRequest request){
        return userService.queryInfo(Long.parseLong(JwtUtils.getUserInfo(request.getHeader("Authorization")).get("userId").toString()));
    }
    //    查询首页信息
    @GetMapping("/mainpage")
    public MainpageVo queryMainpageVo(HttpServletRequest httpServletRequest){
        return userService.queryMainpageVo(httpServletRequest);
    }
    @GetMapping("/id")
    public User queryUser(HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        return userService.queryUser(userId);
    }
    @GetMapping("/info/basic")
    public UserBasicInfoVo queryUserBasicInfoVo(HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        return userService.queryUserBasicInfoVo(userId);
    }
    @PostMapping("/add/file")
    void addUsersFile(MultipartFile multipartFile) throws IOException{
        userService.addUsers(multipartFile);
    }
}
